package com.studyroom.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.studyroom.common.Result;
import com.studyroom.entity.Notice;
import com.studyroom.service.NoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/notices")
public class AdminNoticeController {

    private static final Logger log = LoggerFactory.getLogger(AdminNoticeController.class);

    private final NoticeService noticeService;

    public AdminNoticeController(NoticeService noticeService) {
        this.noticeService = noticeService;
    }

    @GetMapping
    public Result<IPage<Notice>> getNotices(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String title,
            @RequestParam(required = false) Integer status) {
        
        IPage<Notice> page = noticeService.getNotices(current, size, title, status);
        
        // 添加调试日志
        if (page.getRecords().size() > 0) {
            Notice firstNotice = page.getRecords().get(0);
            log.debug("First notice data:");
            log.debug("- createdAt: {}", firstNotice.getCreatedAt());
            log.debug("- createdAt type: {}", firstNotice.getCreatedAt().getClass().getName());
            log.debug("- createdAt toString: {}", firstNotice.getCreatedAt().toString());
        }
        
        return Result.success(page);
    }
} 